<template>
  <div><Chart :option="chartOption" style="height: 400px" /></div>
</template>

<script>
import Chart from "../../components/chart";
import request from "../../utils/request";
export default {
  data() {
    return {
      chartOption:{}
    };
  },
  methods: {
    getChartData() {
      request({
        url:"api/dashboard/chart",
        method:'get',
        params: { Id: 123 }
      }).then((response) => {
        this.chartOption = {
          title: {
            text: "ECharts 入门示例",
          },
          tooltip: {},
          legend: {
            data: ["销量"],
          },
          xAxis: {
            data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
          },
          yAxis: {},
          series: [
            {
              name: "销量",
              type: "bar",
              data: response.data,
            },
          ],
        };
      });
    },
  },
  components: {
    Chart,
  },
  mounted() {
    this.getChartData();
    this.interval = setInterval(() => {
       this.getChartData();
    }, 3000);
  },
  beforeDestroy() {
    clearInterval(this.interval);
  },
};
</script>

